<%@page import="com.grom.service.GcmsUserService"%>
<%@page import="com.grom.util.Constants"%>
<%@page import="com.grom.service.CustomerService"%>
<%@page import="com.grom.po.Customer"%>
<%@page import="com.grom.util.SecurityUtil"%>
<%@page import="com.grom.po.GcmsUser"%>
<%@page import="com.grom.po.Store"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/icon.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.easyui.min.js"></script>

<script type="text/javascript">
<%
if(session.getAttribute("USER")!=null&&session.getAttribute("USER").equals("ADMIN")){
	%>
	currentUserId="ADMIN";
	<%
}
if(session.getAttribute("USER")!=null&&session.getAttribute(Constants.KEY_USER_SESSION)!=null){
	%>
	currentUserId="<%=((GcmsUser)session.getAttribute(Constants.KEY_USER_SESSION)).getID() %>";
	<%
}
%>
$(function(){
	$('#loginInfoEdit').dialog({  
	    title : '店铺信息 录入',  
	    modal: true,  
	    collapsible : true,    
	    resizable : true   
	});  
	$('#loginInfoEdit').dialog('close');
});


function showAddDialog(){
	$('input').each(function(){
		$(this).val('');
	});
	$('select').each(function(){
		$(this).val('');
	});
	$('#save').linkbutton('enable');
	$('#loginInfoEdit').dialog('open');
}

function loginInfoEdit(){
	var canSub = true;
	$('input').each(function(){
		if($(this).attr("required")=="true"){
			if($(this).val()==""){
				$(this).focus();
				canSub =false;
				return;
			}
		}
	});
	$('select').each(function(){
		if($(this).attr("required")=="true"){
			if($(this).val()==""){
				$(this).focus();
				canSub =false;
				return;
			}
		}
	});
	if(canSub){
		$('#storeInfoForm').submit();
	}
}
function viewDetail(){
	var itemId =  $('#tt').datagrid('getSelected').itemid;
	$.ajax({
	    url: '<%=request.getContextPath()%>/StoreAction/getDetail.do?itemid='+itemId,
	    type: 'GET',
	    timeout: 1000,
	    error: function(){
	        alert('Error getting response!');
	    },
	    success: function(json){
	        var store = eval(json);
	        $('#ID').val(store.ID);
	        $('#shopID').val(store.shopID);
	        $('#codeOfABDCode').val(store.codeOfABDCode);
	        $('#managerOfABD').val(store.managerOfABD);
	        $('#phoneOfABDManager').val(store.phoneOfABDManager);
	        $('#countSystem').val(store.countSystem);
	        $('#chargeSystem').val(store.chargeSystem);
	        $('#storeCoverSystem').val(store.storeCoverSystem);
	        $('#storeAddress').val(store.storeAddress);
	        $('#storeManeger').val(store.storeManeger);
	        $('#phoneOfStoreManager').val(store.phoneOfStoreManager);
	        $('#urgentStoreContactor').val(store.urgentStoreContactor);
	        $('#urgentStoreContactPhone').val(store.urgentStoreContactPhone);
	        $('#projectManager').val(store.projectManager);
	        $('#phoneOfProjectManager').val(store.phoneOfProjectManager);
	        $('#broadBandAccount').val(store.broadBandAccount);
	        $('#broadBandPassword').val(store.broadBandPassword);
	        $('#areaOfStore').val(store.areaOfStore);
	        $('#bestSaleOfStore').val(store.bestSaleOfStore);
	        $('#clothType').val(store.clothType);
	        $('#chargeScope').val(store.chargeScope);
	        $('#dealScope').val(store.dealScope);
	        $('#dealArea').val(store.dealArea);
	        $('#operatePermission').val(store.operatePermission);
	        $('#operateTime').val(store.operateTime);
	        $('#independencyElectric').val(store.independencyElectric);
	        $('#broadBandAmount').val(store.broadBandAmount);
	        $('#faxNum').val(store.faxNum);
	        $('#Addresss').val(store.Addresss);
	        $('#Phone').val(store.Phone);
	        $('#Email').val(store.Email);
	        $('#brandName').val(store.brandName);
	        $('#webSite').val(store.webSite);
	        $('#isABDUser').val(store.isABDUser);
	        $('#isInRequisition').val(store.isInRequisition);
	        $('#chunnelMaterial').val(store.chunnelMaterial);
	        $('#heightOfChunnel').val(store.heightOfChunnel);
	        $('#numOfChunnel').val(store.numOfChunnel);
	        $('#monthlyAverageSale').val(store.monthlyAverageSale);
	        $('#userId').val(store.userId);
	        $('#customerId').val(store.customerId);
	        if(currentUserId == "ADMIN"||store.userId == currentUserId ||store.userId==""){
	        	$('#save').linkbutton('enable');
	        }else{
	        	$('#save').linkbutton('disable');
	        }
			$('#loginInfoEdit').dialog('open');
	    }
	});
}

function doDelete(){
	var itemId =  $('#tt').datagrid('getSelected').itemid;
	if (itemId){  
        $.messager.confirm('Confirm','Are you sure you want to remove this user?',function(r){  
            if (r){  
				$('#deleteId').val(itemId);
				$('#deleteForm').submit();
            }  
        });  
    } 
}

function doSearch(){
	$('#searchForm').submit();
}
</script>
</head>
<body>
<div style="display: none;">
	<form name="deleteForm" id="deleteForm" action="<%=request.getContextPath() %>/StoreAction/doDelete.do">
		<input type="text" name="deleteId" id="deleteId"/>
	</form>
</div>
<div style="font-size: 10px;">
	<form id="searchForm" name="searchForm" action="<%=request.getContextPath() %>/StoreAction/conditionSelect.do" method="post">
      <label>店铺地址：</label>  
      <input type="text" name="storeAddress_s" id="storeAddress_s" ></input>   
      <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearch()">search</a>
    </form>
</div>
<table id="tt" class="easyui-datagrid"   singleSelect="true"
        title="店铺基本信息" iconCls="icon-save"  
        toolbar="#tb">  
    <thead>  
        <tr>  
            <th field="itemid" width="80" hidden="true">Item ID</th>  
            <th field="codeOfABDCode" width="280">店铺地址</th>  
            <th field="managerOfABD" width="120">店铺负责人</th>  
            <th field="phoneOfABDManager" width="150">店铺负责人联系电话</th>
            <th field="sales" width="150">销售人员</th>  
        </tr>  
    </thead>  
    <tbody>     
    	<%
    		List<Store> allStores = (List<Store>)request.getAttribute("allStores");
    		for(Store store : allStores){
    	%>
        <tr>                             
            <td><%=store.getID() %></td>              
            <td><%=store.getStoreAddress() %></td>              
            <td><%=store.getStoreManeger() %></td>              
            <td><%=store.getPhoneOfStoreManager() %></td>  
            <td><%=GcmsUserService.instance.getUserByID(store.getUserId()).getUserName() %></td>                        
        </tr>  
    	<%
    		}
    	%>                         
    </tbody>
</table>  
<div id="tb">  
 <%
	if(session.getAttribute("USER")!=null){
%>
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="showAddDialog()">Add</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true" onclick="viewDetail()">view/update</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="doDelete()">Delete</a> 
    <a href="#" class="easyui-linkbutton" iconCls="icon-back" plain="true" onclick="javascript:alert('我觉着这个翻页不实用，设置下条件吧！')">pre page</a> 
    <a href="#" class="easyui-linkbutton" iconCls="icon-back" plain="true" onclick="javascript:alert('我觉着这个翻页不实用，设置下条件吧！')">next page</a> 
<%
	}
%> 
</div>  


<!-- 编辑 -->  
<div id="loginInfoEdit"  
    style="padding: 5px; width: 600px; height: 250px;">  
    <h5 id="loginInfoEdit_message" style="color: red;"></h5>  
    <div class="ToolTip_Form" id="table_loginInfoEdit" onkeydown="if(event.keyCode==13){loginInfoEdit();}">  
       <form id="storeInfoForm" name="storeInfoForm" action="<%=request.getContextPath() %>/StoreAction/doSave.do" method="post">
       <input type="hidden"" name="ID" id="ID" value=""/>
       <ul>    
			<li>  
                <label>店铺地址：</label>  
                <input type="text" class="easyui-validatebox" name="storeAddress" id="storeAddress" required="true"></input>  
            </li>  
            <li>  
                <label>店铺负责人：</label>  
                <input type="text" class="easyui-validatebox" name="storeManeger" id="storeManeger" required="true"></input>  
            </li> 
            <li>  
                <label>店铺负责人联系电话：</label>  
                <input type="text" class="easyui-validatebox" name="phoneOfStoreManager" id="phoneOfStoreManager" ></input>  
            </li>  
            <li>  
                <label>销售人员：</label>  
                <select id="userId" name="userId" required="true">
                	<option value="">无</option>
                	<%
                		List<GcmsUser> users = SecurityUtil.getAllUser();
                		for(GcmsUser user : users){
                			%>
                			<option value="<%=user.getID() %>"><%=user.getUserName() %></option>
                			<%
                		}
                	%>
                </select>
            </li> 
             <li>  
                <label>所属公司：</label>  
                <select id="customerId" name="customerId" required="true">
                	<option value="">无</option>
                	<%
                		List<Customer> customers = CustomerService.instance.getAllCustomer();
                		for(Customer cus : customers){
                			%>
                			<option value="<%=cus.getID() %>"><%=cus.getCustomerName() %></option>
                			<%
                		}
                	%>
                </select>
            </li> 
            
            
            <!--     
            <li>  
                <label>shop_id：</label>  
                <input type="text" class="easyui-validatebox" name="shopID" id="shopID" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>ABD店代码：</label>  
                <input type="text" class="easyui-validatebox" name="codeOfABDCode" id="codeOfABDCode" maxlength_d="20" required="true"></input>  
            </li> 
            <li>  
                <label>ABD负责人：</label>  
                <input type="text" class="easyui-validatebox" name="managerOfABD" id="managerOfABD" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>ABD负责人联系电话：</label>  
                <input type="text" class="easyui-validatebox" name="phoneOfABDManager" id="phoneOfABDManager" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>安装何种计数系统：</label>  
                <input type="text" class="easyui-validatebox" name="countSystem" id="countSystem" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>安装何种收银系统：</label>  
                <input type="text" class="easyui-validatebox" name="chargeSystem" id="chargeSystem" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>安装何种巡店系统：</label>  
                <input type="text" class="easyui-validatebox" name="storeCoverSystem" id="storeCoverSystem" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>店铺紧急联系人：</label>  
                <input type="text" class="easyui-validatebox" name="urgentStoreContactor" id="urgentStoreContactor" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>店铺紧急联系人联系电话：</label>  
                <input type="text" class="easyui-validatebox" name="urgentStoreContactPhone" id="urgentStoreContactPhone" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>工程负责人：</label>  
                <input type="text" class="easyui-validatebox" name="projectManager" id="projectManager" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>工程负责人联系电话：</label>  
                <input type="text" class="easyui-validatebox" name="phoneOfProjectManager" id="phoneOfProjectManager" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>店铺宽带账号：</label>  
                <input type="text" class="easyui-validatebox" name="broadBandAccount" id="broadBandAccount" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>店铺宽带密码：</label>  
                <input type="text" class="easyui-validatebox" name="broadBandPassword" id="broadBandPassword" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>店铺面积(平方米)：</label>  
                <input type="text" class="easyui-validatebox" name="areaOfStore" id="areaOfStore" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>店铺年最高销售额：</label>  
                <input type="text" class="easyui-validatebox" name="bestSaleOfStore" id="bestSaleOfStore" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>服饰类型：</label>  
                <input type="text" class="easyui-validatebox" name="clothType" id="clothType" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>价格区间：</label>  
                <input type="text" class="easyui-validatebox" name="chargeScope" id="chargeScope" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>经营范围：</label>  
                <input type="text" class="easyui-validatebox" name="dealScope" id="dealScope" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>经营地域（省、市）：</label>  
                <input type="text" class="easyui-validatebox" name="dealArea" id="dealArea" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>经营权：</label>  
                <input type="text" class="easyui-validatebox" name="operatePermission" id="operatePermission" maxlength_d="20" required_d="true"></input>  
            </li> 
             <li>  
                <label>经营时间：</label>  
                <input type="text" class="easyui-validatebox" name="operateTime" id="operateTime" maxlength_d="20" required_d="true"></input>  
            </li> 
             <li>  
                <label>供电是否独立：</label>  
                <input type="text" class="easyui-validatebox" name="independencyElectric" id="independencyElectric" maxlength_d="20" required_d="true"></input>  
            </li> 
             <li>  
                <label>宽带带宽：</label>  
                <input type="text" class="easyui-validatebox" name="broadBandAmount" id="broadBandAmount" maxlength_d="20" required_d="true"></input>  
            </li> 
             <li>  
                <label>联系传真：</label>  
                <input type="text" class="easyui-validatebox" name="faxNum" id="faxNum" maxlength_d="20" required_d="true"></input>  
            </li> 
             <li>  
                <label>联系地址/总部地址：</label>  
                <input type="text" class="easyui-validatebox" name="Addresss" id="Addresss" maxlength_d="20" required_d="true"></input>  
            </li> 
             <li>  
                <label>联系电话：</label>  
                <input type="text" class="easyui-validatebox" name="Phone" id="Phone" maxlength_d="20" required_d="true"></input>  
            </li> 
             <li>  
                <label>联系电邮：</label>  
                <input type="text" class="easyui-validatebox" name="Email" id="Email" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>品牌名称：</label>  
                <input type="text" class="easyui-validatebox" name="brandName" id="brandName" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>品牌网站：</label>  
                <input type="text" class="easyui-validatebox" name="webSite" id="webSite" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>是否ABD客户：</label>  
                <input type="text" class="easyui-validatebox" name="isABDUser" id="isABDUser" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>是否提出施工申请：</label>  
                <input type="text" class="easyui-validatebox" name="isInRequisition" id="isInRequisition" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>通道顶部材质：</label>  
                <input type="text" class="easyui-validatebox" name="chunnelMaterial" id="chunnelMaterial" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>通道举架高度：</label>  
                <input type="text" class="easyui-validatebox" name="heightOfChunnel" id="heightOfChunnel" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>通道带宽,通道数量：</label>  
                <input type="text" class="easyui-validatebox" name="numOfChunnel" id="numOfChunnel" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>月平均销售额：</label>  
                <input type="text" class="easyui-validatebox" name="monthlyAverageSale" id="monthlyAverageSale" maxlength_d="20" required_d="true"></input>  
            </li> 
			 -->
			 
            <li>  
            	<a id="save" name="save" href="#" class="easyui-linkbutton" onclick="loginInfoEdit();">保存</a>
            	<a href="#" class="easyui-linkbutton" onclick="$('#loginInfoEdit').dialog('close');">放弃操作</a>
            </li>  
        </ul>  
       </form>
    </div>  
</div>  
</body>
</html>